const { defineConfig } = require('@vue/cli-service')
const Mock = require('mockjs')
const { tab } = Mock.mock({
  'tab|6': [
    {
      img: '@image(120x180,@color,image)',
      title: '@ctitle(4)',
    },
  ],
})
let { list, authorList } = Mock.mock({
  'list|30': [
    {
      id: '@id',
      src: '@image(180x120,@color,image)',
      title: '@ctitle(5,10)',
      word: '@cword(8,12)',
      'price|100-200': 1,
    },
  ],
  'authorList|20': [
    {
      image: '@image(180x120,@color,image)',
      name: '@cname(4,5)',
      title: '@ctitle',
      tag: '白金',
      id: '@id',
    },
  ],
})
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    setupMiddlewares(mid, { app }) {
      app.get('/api/tab', (req, res) => {
        res.send({
          code: 200,
          tab,
        })
      })
      app.get('/api/list', (req, res) => {
        res.send({
          code: 200,
          list,
        })
      })

      app.get('/api/detail', (req, res) => {
        let { id } = req.query
        let item = list.find((item) => item.id === id)
        res.send({
          code: 200,
          item,
        })
      })
      app.get('/api/authorList', (req, res) => {
        res.send({
          code: 200,
          authorList,
        })
      })
      return mid
    },
  },
})
